/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.merashehar.db.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author binkam
 */
public class ConnectionManager {
    private Connection jdbcConnection = null;
    public ConnectionManager(){
        loadDriver("net.sourceforge.jtds.jdbc.Driver");
        //loadDriver("com.mysql.jdbc.Driver");
        
    }
    
    public void loadDriver(String driverClass)
    {
        try{
            Class.forName(driverClass);
        }catch(ClassNotFoundException e){
            Logger.getLogger(ConnectionManager.class.getName()).log(Level.SEVERE, null, e);
        }
    }
    
    public Connection getConnection(){
        try {
            if(jdbcConnection==null)
            jdbcConnection = DriverManager.getConnection("jdbc:jtds:sqlserver://69.73.147.53:1433/merashehar", "msadmin", "admin@123");
            //jdbcConnection = DriverManager.getConnection("jdbc:jtds:sqlserver://10.156.157.202:1433/incubed", "incubed", "incubed");
            //jdbcConnection = DriverManager.getConnection("jdbc:mysql://localhost:3306/merashehar", "root", "");
        } catch (SQLException ex) {
            Logger.getLogger(ConnectionManager.class.getName()).log(Level.SEVERE, null, ex);
        }
        return jdbcConnection;
    }
    
    public static void main(String[] args) {
        ConnectionManager c = new ConnectionManager();
        System.out.println("Connection "+c.getConnection());
         
    }
    
}
